home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / MEM2SCX.ASM < prev    next >
Assembly Source File  |  1995-02-21  |  7KB  |  145 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Mode X (320x240, 256 colors) system memory-to-display memory masked copy 
  6. ; routine. Not particularly fast; images for which performance is critical 
  7. ; should be stored in off-screen memory and copied to screen via latches. Works
  8. ; on all VGAs. Copies up to but not including column at SourceEndX and row at 
  9. ; SourceEndY. No clipping is performed. Mask and source image are both byte-
  10. ; per-pixel, and must be of same widths and reside at same coordinates in their
  11. ; respective bitmaps. Assembly code tested with TASM 2.0. C near-callable as:
  12. ;    void CopySystemToScreenMaskedX(int SourceStartX,
  13. ;       int SourceStartY, int SourceEndX, int SourceEndY,
  14. ;       int DestStartX, int DestStartY, char * SourcePtr,
  15. ;       unsigned int DestPageBase, int SourceBitmapWidth,
  16. ;       int DestBitmapWidth, char * MaskPtr);
  17.  
  18. SC_INDEX equ    03c4h   ;Sequence Controller Index register port
  19. MAP_MASK equ    02h     ;index in SC of Map Mask register
  20.  
  21. parms   struc
  22.         dd      2 dup (?) ;pushed BP and return address
  23. SourceStartX dd ?       ;X coordinate of upper left corner of source
  24.                         ; (source is in system memory)
  25. SourceStartY dd ?       ;Y coordinate of upper left corner of source
  26. SourceEndX   dd ?       ;X coordinate of lower right corner of source
  27.                         ; (the column at EndX is not copied)
  28. SourceEndY   dd ?       ;Y coordinate of lower right corner of source
  29.                         ; (the row at EndY is not copied)
  30. DestStartX   dd ?       ;X coordinate of upper left corner of dest
  31.                         ; (destination is in display memory)
  32. DestStartY   dd ?       ;Y coordinate of upper left corner of dest
  33. SourcePtr    dd ?       ;pointer in DS to start of bitmap which source resides
  34. DestPageBase dd ?       ;base offset in display memory of page in
  35.                         ; which dest resides
  36. SourceBitmapWidth dd ?  ;# of pixels across source bitmap (also must
  37.                         ; be width across the mask)
  38. DestBitmapWidth   dd ?  ;# of pixels across dest bitmap (must be multiple of 4)
  39. MaskPtr      dd ?       ;pointer in DS to start of bitmap in which mask
  40.                         ; resides (byte-per-pixel format, just like the source 
  41.                         ; image; 0-bytes mean don't copy corresponding source 
  42.                         ; pixel, 1-bytes mean do copy)
  43. parms   ends
  44.  
  45. RectWidth equ   -4      ;local storage for width of rectangle
  46. RectHeight equ  -8      ;local storage for height of rectangle
  47. LeftMask equ    -10     ;local storage for left rect edge plane mask
  48. STACK_FRAME_SIZE equ 10
  49.  
  50.         @dseg
  51.  
  52.         extrn   SCREEN_SEG:dword
  53.  
  54.         ends
  55.  
  56.         @cseg
  57.  
  58.         public  _CopySystemToScreenMaskedX
  59. _CopySystemToScreenMaskedX proc    near
  60.         push    ebp      ;preserve caller's stack frame
  61.         mov     ebp,esp  ;point to local stack frame
  62.         sub     esp,STACK_FRAME_SIZE ;allocate space for local vars
  63.         push    esi      ;preserve caller's register variables
  64.         push    edi
  65.         push    ebx
  66.  
  67.         mov     eax, [ebp+SourceBitmapWidth]
  68.         mul     [ebp+SourceStartY] ;top source rect scan line
  69.         add     eax,[ebp+SourceStartX]
  70.         mov     ebx,eax
  71.         add     eax,[ebp+SourcePtr] ;offset of first source rect pixel
  72.         mov     esi,eax             ; in DS
  73.         add     ebx,[ebp+MaskPtr] ;offset of first mask pixel in DS
  74.         
  75.         mov     eax, [ebp+DestBitmapWidth]
  76.         shr     eax,2            ;convert to width in addresses
  77.         mov     [ebp+DestBitmapWidth],eax ;remember address width
  78.         mul     [ebp+DestStartY] ;top dest rect scan line
  79.         mov     edi, [ebp+DestStartX]
  80.         mov     ecx,edi
  81.         shr     edi,2    ;X/4 = offset of first dest rect pixel in scan line
  82.         add     edi,eax   ;offset of first dest rect pixel in page
  83.         add     edi,[ebp+DestPageBase] ;offset of first dest rect pixel
  84.                         ; in display memory
  85.         and     cl,011b ;CL = first dest pixel's plane
  86.         mov     al,11h  ;upper nibble comes into play when plane wraps
  87.                         ; from 3 back to 0
  88.         shl     al,cl   ;set the bit for the first dest pixel's plane
  89.         mov     [ebp+LeftMask],al ; in each nibble to 1
  90.  
  91.         mov     eax,[ebp+SourceEndX]   ;calculate # of pixels across
  92.         sub     eax,[ebp+SourceStartX] ; rect
  93.         jle     CopyDone        ;skip if 0 or negative width
  94.         mov     [ebp+RectWidth],eax
  95.         sub     [ebp+SourceBitmapWidth],eax
  96.                     ;distance from end of one source scan line to start of next
  97.         mov     eax,[ebp+SourceEndY]
  98.         sub     eax,[ebp+SourceStartY] ;height of rectangle
  99.         jle     CopyDone        ;skip if 0 or negative height
  100.         mov     [ebp+RectHeight],eax
  101.         mov     dx,SC_INDEX     ;point to SC Index register
  102.         mov     al,MAP_MASK
  103.         out     dx,al           ;point SC Index reg to the Map Mask
  104.         inc     dx              ;point DX to SC Data reg
  105.  
  106.         add     edi, [SCREEN_SEG] ; point edi to video
  107. CopyRowsLoop:
  108.         mov     al,[ebp+LeftMask]
  109.         mov     ecx,[ebp+RectWidth]
  110.         push    edi      ;remember the start offset in the dest
  111. CopyScanLineLoop:
  112.         cmp     byte ptr [ebx],0 ;is this pixel mask-enabled?
  113.         jz      MaskOff         ;no, so don't draw it
  114.                                 ;yes, draw the pixel
  115.         out     dx,al           ;set the plane for this pixel
  116.         mov     ah,[esi]        ;get the pixel from the source
  117.         mov     [edi],ah        ;copy the pixel to the screen
  118. MaskOff:
  119.         inc     ebx              ;advance the mask pointer
  120.         inc     esi              ;advance the source pointer
  121.         rol     al,1            ;set mask for next pixel's plane
  122.         adc     di,0            ;advance destination address only when
  123.                                 ; wrapping from plane 3 to plane 0
  124.         loop    CopyScanLineLoop
  125.         pop     edi              ;retrieve the dest start offset
  126.         add     edi,[ebp+DestBitmapWidth] ;point to the start of the
  127.                                         ; next scan line of the dest
  128.         add     esi,[ebp+SourceBitmapWidth] ;point to the start of the
  129.                                         ; next scan line of the source
  130.         add     ebx,[ebp+SourceBitmapWidth] ;point to the start of the
  131.                                         ; next scan line of the mask
  132.         dec     dword ptr [ebp+RectHeight] ;count down scan lines
  133.         jnz     CopyRowsLoop
  134. CopyDone:
  135.         pop     ebx
  136.         pop     edi      ;restore caller's register variables
  137.         pop     esi
  138.         mov     esp,ebp  ;discard storage for local variables
  139.         pop     ebp      ;restore caller's stack frame
  140.         ret
  141. _CopySystemToScreenMaskedX endp
  142.         ends
  143.         end
  144.  
  145.